﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.TranslateApprove.Model;
using Yipusoft.TranslateApprove.BLL;

public partial class System_ApproveRoles : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGV();
        }
    }

    void BindGV()
    {
        gvRoles.DataSource = Roles.GetList();
        gvRoles.DataBind();
    }

    protected void gvChemical_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }
    protected void gvChemical_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblID = e.Row.FindControl("lblID") as Label;
            lblID.Text = Convert.ToString(e.Row.RowIndex + 1);
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");

        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        RoleInfo info = new RoleInfo();
        info.DutyName = DutyName.Text;
        if (Roles.Insert(info) != -1)
        {
            BindGV();
        }
    }
    protected void gvRoles_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        if (Members.GetList(Convert.ToInt32(gvRoles.DataKeys[e.RowIndex].Value)).Count > 0)
        {
            Prompt.Text = "此角色中已存在用户,不可删除！";
        }
        else
        {
            Roles.Delete(Convert.ToInt32(gvRoles.DataKeys[e.RowIndex].Value));
            BindGV();
            Prompt.Text = "删除成功！";
        }
    }
    protected void gvRoles_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvRoles.EditIndex = e.NewEditIndex;
        BindGV();
    }
    protected void gvRoles_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gvRoles.EditIndex = -1;
        BindGV();
    }

    protected void gvRoles_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

        TextBox txtName = gvRoles.Rows[e.RowIndex].FindControl("txtName") as TextBox;
        RoleInfo info = new RoleInfo();
        info.DID = Convert.ToInt32(gvRoles.DataKeys[e.RowIndex].Value);
        info.DutyName = txtName.Text;
        Roles.Update(info);
        gvRoles.EditIndex = -1;
        BindGV();
    }
}
